<!DOCTYPE html>
<html lang="en">
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理
            <small>预约订单管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约订单管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <!--页面主体-->
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <!--根据日期查询-->
                <template>
                    <el-date-picker
                            v-model="queryDate"
                            type="daterange"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            unlink-panels style="width: 240px">
                    </el-date-picker>
                    <!--下拉预约类型查询-->
                    <el-select style="width: 125px" v-model="pagination.queryString.orderType" clearable
                               placeholder="请选择">
                        <el-option
                                v-for="t in selectType"
                                :key="t.value"
                                :value="t.value">
                        </el-option>
                    </el-select>
                    <!--下拉预约状态查询-->
                    <el-select style="width: 125px" v-model="pagination.queryString.orderStatus" clearable
                               placeholder="请选择">
                        <el-option
                                v-for="s in selectStatus"
                                :key="s.value"
                                :value="s.value">
                        </el-option>
                    </el-select>
                    <!--下拉套餐名称查迅-->
                    <el-select style="width: 200px" id="setfoodSelect" v-model="pagination.queryString.setmealName"
                               clearable
                               placeholder="请选择">
                        <el-option
                                v-for="food in selectSetfood"
                                :key="food.value"
                                :value="food.value">
                        </el-option>
                    </el-select>
                </template>
                <!--姓名电话查询-->
                <el-input placeholder="会员姓名/手机号" v-model="pagination.queryString.nameOrPhone" style="width: 150px;"
                          class="filter-item" clearable></el-input>
                <el-button @click="handleCurrentChange(1)" class="dalfBut">查询</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="member.name" label="会员姓名" align="center"></el-table-column>
                <el-table-column prop="member.phoneNumber" label="电话号码" align="center"></el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="id" label="预约id" align="center" v-if="false"></el-table-column>
                <el-table-column label="预约状态" align="center">
                    <template slot-scope="scope">
                        <span>{{scope.row.orderStatus}}</span>
                        <el-switch
                                v-model="scope.row.orderStatus"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                                active-value="未到诊"
                                inactive-value="已到诊"
                                @change="changeStatus(scope.row)">
                        </el-switch>
                    </template>
                </el-table-column>
                <el-table-column prop="setmeal.name" label="套餐名称" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleCreate(scope.row)">建议</el-button>
                        <el-button size="mini" type="danger" @click="handleUpdate(scope.row)">更新</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!--分页插件-->
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>

            <div class="add-form">
                <el-dialog title="新增干预" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">

                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px" :model="formDataAdvise">

                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="健康建议">
                                                <el-input v-model="formDataAdvise.doctorAdvice"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                </el-form>
                            </el-tab-pane>

                            <el-tab-pane label="运动库" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>运动编码</th>
                                            <th>运动名称</th>
                                            <th>运动助记码</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="exerciseIds" type="checkbox" :value="'c'+c.id">
                                            </td>
                                            <td><label :for="c.id">{{c.id}}</label></td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.code}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>

                            <el-tab-pane label="膳食库" name="third">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>膳食编码</th>
                                            <th>膳食名称</th>
                                            <th>膳食说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="d in tableData1">
                                            <td>
                                                <input :id="d.id" v-model="foodIds" type="checkbox" :value="'d'+d.id">
                                            </td>
                                            <td><label :for="d.id">{{d.id}}</label></td>
                                            <td><label :for="d.id">{{d.name}}</label></td>
                                            <td><label :for="d.id">{{d.explain}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>


                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
            <div class="add-form">
                <el-dialog title="编辑套餐" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">

                            <el-tab-pane label="基本信息" name="first" >
                                <el-form label-position="right" label-width="100px" :model="editFormDataAdvice">

                                    <el-row>
                                        <el-col :span="48">
                                            <el-form-item label="健康建议">
                                                <el-input v-model="editFormDataAdvice.doctorAdvice"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                </el-form>
                            </el-tab-pane>

                            <el-tab-pane label="运动库" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>运动编码</th>
                                            <th>运动名称</th>
                                            <th>运动助记码</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="exerciseIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td><label :for="c.id">{{c.id}}</label></td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.code}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>

                            <el-tab-pane label="膳食库" name="third">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>膳食编码</th>
                                            <th>膳食名称</th>
                                            <th>膳食说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="d in tableData1">
                                            <td>
                                                <input :id="d.id" v-model="foodIds" type="checkbox" :value="+d.id">
                                            </td>
                                            <td><label :for="d.id">{{d.id}}</label></td>
                                            <td><label :for="d.id">{{d.name}}</label></td>
                                            <td><label :for="d.id">{{d.explains}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>


<script>
    new Vue({
        el: '#app',
        data: {
            pagination: {
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: {
                    startDate: null,  //开始日期
                    endDate: null,  //结束日期
                    orderType: null,  //预约类型
                    orderStatus: null,  //预约状态
                    setmealName: null,  //套餐名称
                    nameOrPhone: null,  //会员姓名或手机号
                }
            },
            queryDate: null,
            selectType: [{value: '微信预约'}, {value: '电话预约'}],
            selectStatus: [{value: '未到诊'}, {value: '已到诊'}],
            selectSetfood: [],
            dataList: [],
            foodIds:[],
            exerciseIds: [],
            status: true,
            dialogFormVisible: false,
            dialogFormVisible4Edit: false, //控制修改窗口显示/隐藏
            activeName: 'first',
            editFormDataAdvice:[],
            editFormDataAdvise:[],
            formDataAdvise:{},
            formData: {
                member: {}
            },  //添加预约的表单信息
            tableData: [],  //套餐信息
            setfoodId: [],
            roleId:[],
            username:{},
            tableData1:{},
            id:[]
        },
        mounted() {
            this.findPage();
        },
        methods: {
            handleCurrentChange(currentPage){
                this.pagination.currentPage = currentPage;
                this.findPage();
            },

            //分页查询
            findPage() {
                //判断是否输入日期查询
                if (this.queryDate != null) {
                    this.pagination.queryString.startDate = getFormateDate(this.queryDate[0]);
                    this.pagination.queryString.endDate = getFormateDate(this.queryDate[1]);
                }
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                }
                axios.post("/orderlist/findPage.do",param).then((res) => {
                    if (res.data.flag) {
                        this.dataList = res.data.data.rows;
                        this.resetQuery();
                        this.pagination.total = res.data.data.total; //数据总条数
                        //查询所有的套餐信息
                        axios.get("/setmeal/findAll.do")
                            .then((res) => {
                                if (res.data.flag) {
                                    this.selectSetfood = [];
                                    res.data.data.forEach(setfood => this.selectSetfood.push({value: setfood.name}));
                                }
                                else
                                    this.$message.error(res.data.message);
                            })
                    }
                    else
                        this.$message.error(res.data.message);
                });
            },
            handleCurrentChange(currentPage) {
                //为模型数据赋值（当前页面）
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            //重置查询条件
            resetQuery() {
                this.pagination.queryString = {};
                this.queryDate=null;
            },
            // 弹出添加窗口
            handleCreate(row){
                this.roleId=row.id;
                this.formDataAdvise={},
                this.resetForm();
                this.dialogFormVisible = true;
                //发送ajax请求，查询所有的检查项信息，转为json，赋值给tableData
                this.activeName = 'first';//默认选中first对应的tab
                this.exerciseIds = [];//重置复选框
                this.foodIds =[];
                axios.get("/exercise/findAll.do").then((res) => {
                    if(res.data.flag){
                        //查询检查项数据成功
                        this.tableData = res.data.data;
                        axios.get("/food/findAll.do").then((res) =>{
                            if(res.data.flag){
                                this.tableData1=res.data.data;
                            }else {
                                this.$message.error(res.data.message);
                            }
                        })
                    }else{
                        //查询检查项数据失败
                        this.$message.error(res.data.message);
                    }
                });
                axios.get("/user/getUsername.do").then((res)=>{
                    this.username=res.data.data;
                })
            },

            handleAdd() {

                let param={
                    doctorAdvice:this.formDataAdvise.doctorAdvice,
                    doctorName:this.username,
                    order_id:this.roleId
                };
                this.dialogFormVisible=false;
                axios.post("/intervention/add.do?exerciseIds=" + this.exerciseIds+"&&foodIds="+this.foodIds,param).then((res) => {
                    //关闭新增窗口
                    if (res.data.flag) {
                        this.findPage();
                        //操作成功
                        this.$message({
                            type: 'success',
                            message: res.data.message
                        });
                    } else {
                        //操作失败
                        this.$message.error(res.data.message);
                    }
                })
            },
            handleUpdate(row) {
                //弹出编辑窗口
                this.dialogFormVisible4Edit = true;
                this.activeName = 'first';
                this.roleId=row.id;
                this.foodIds=[],
                this.exerciseIds=[],

                //发送ajax请求，根据检查组ID查询当前检查组数据，用于基本信息的回
                // 显
                axios.get("/intervention/findById.do?interventionId=" +this.roleId).then((res) => {
                    if(res.data.flag){
                        //查询到数据
                        this.editFormDataAdvice = res.data.data;
                         this.id=this.editFormDataAdvice.id
                    }else{
                        //查询数据失败
                        this.$message.error(res.data.message);
                    }
                });
                //发送ajax请求，查询所有的检查项数据，用于展示检查项列表
                axios.get("/exercise/findAll.do").then((res) => {
                    if(res.data.flag){
                        //查询检查项数据成功
                        this.tableData = res.data.data;
                        //发送ajax请求，根据检查组ID查询当前检查组包含的检查项ID，用于页面复选框回显
                        axios.get("/intervention/findexerciseIdsByinterventionId.do?interventionId=" + this.id).then((res) => {
                            if(res.data.flag){
                                this.exerciseIds = res.data.data;
                            }else{
                                this.$message.error(res.data.message);
                            }
                        });
                    }else{
                        //查询检查项数据失败
                        this.$message.error(res.data.message);
                    }
                });
                axios.get("/food/findAll.do").then((res) => {
                    if(res.data.flag){
                        //查询检查项数据成功
                        this.tableData1 = res.data.data;
                        //发送ajax请求，根据检查组ID查询当前检查组包含的检查项ID，用于页面复选框回显
                        axios.get("/intervention/findfoodIdsByinterventionId.do?interventionId=" + this.id).then((res) => {
                            if(res.data.flag){
                                this.foodIds = res.data.data;
                            }else{
                                this.$message.error(res.data.message);
                            }
                        });
                    }else{
                        //查询检查项数据失败
                        this.$message.error(res.data.message);
                    }
                });

            },
            resetForm(){
                this.formDataAdvise={}
            },
            handleEdit() {
                let param={
                    doctorAdvice:this.editFormDataAdvice.doctorAdvice,
                    order_id:this.roleId,
                    id:this.id,
                };
                        //发送ajax请求，将修改后的表单数据（检查组基本信息、勾选的检查项）提交到后台进行处理
                        axios.post("/intervention/edit.do?exerciseIds=" + this.exerciseIds+"&&foodIds="+this.foodIds,param).then((res) => {
                            //关闭编辑窗口
                            this.dialogFormVisible4Edit = false;
                            if (res.data.flag) {
                                //操作成功
                                this.$message({
                                    type: 'success',
                                    message: res.data.message
                                });
                            } else {
                                //操作失败
                                this.$message.error(res.data.message);
                            }
                        }).finally(()=>{
                            this.findPage();
                            this.dialogFormVisible4Edit = false;
                        })
                    },
        }
    })
</script>

</html>